package beikai.com.assistant.exception;

import beikai.com.assistant.common.exception.EleException;
import beikai.com.assistant.common.util.R;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: 小北(xiaobei @ dtstack.com)
 * @program: electricity-assistant
 * @description:
 * @create: 2021-12-19 09:53
 **/
@RestControllerAdvice
public class GlobalExceptionConfig {
    /**
     * 业务异常处理
     * @param e
     * @return ErrorInfo
     */
    @ExceptionHandler({EleException.class})
    public ResponseEntity businessExceptionHandler(HttpServletRequest request, EleException e) throws EleException {
        return new ResponseEntity(R.fail(HttpStatus.INTERNAL_SERVER_ERROR.value(),e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
